package elijah.base;

import android.content.Context;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import java.io.File;

public class Config implements Parcelable {
    private String ip;
    private int port = 8080;
    private String ftpIp;
    private int ftpPort = 21;
    private String ftpUser = "MES";
    private String ftpPsw = "962464ff.";
    private int picPort = 8080;


    private String project;

    public String getLocalRootDir() {

        File base = AppBase.get().getAppContext().getExternalFilesDir(null);
        if (!base.exists()) {
            base = AppBase.get().getAppContext().getDir("mes", Context.MODE_PRIVATE);
        }
        Log.e("base path", base.getPath());
        return base.getPath() + "/MES";
    }


    public int getFtpPort() {
        return ftpPort;
    }

    public Config setFtpPort(int ftpPort) {
        this.ftpPort = ftpPort;
        return this;
    }

    public int getPicPort() {
        return picPort;
    }

    public Config setPicPort(int picPort) {
        this.picPort = picPort;
        return this;
    }

    public String getIp() {
        return ip;
    }

    public Config setIp(String ip) {
        this.ip = ip;
        return this;
    }

    public int getPort() {
        return port;
    }

    public Config setPort(int port) {
        this.port = port;
        return this;
    }

    public String getFtpIp() {
        return ftpIp == null ? ip : ftpIp;
    }

    public Config setFtpIp(String ftpIp) {
        this.ftpIp = ftpIp;
        return this;
    }

    public String getFtpUser() {
        return ftpUser;
    }

    public Config setFtpUser(String ftpUser) {
        this.ftpUser = ftpUser;
        return this;
    }

    public String getFtpPsw() {
        return ftpPsw;
    }

    public Config setFtpPsw(String ftpPsw) {
        this.ftpPsw = ftpPsw;
        return this;
    }

    public String getProject() {
        return project;
    }

    public Config setProject(String project) {
        this.project = project;
        return this;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.ip);
        dest.writeInt(this.port);
        dest.writeString(this.ftpIp);
        dest.writeInt(this.ftpPort);
        dest.writeString(this.ftpUser);
        dest.writeString(this.ftpPsw);
        dest.writeInt(this.picPort);
        dest.writeString(this.project);
    }

    public Config() {
    }

    protected Config(Parcel in) {
        this.ip = in.readString();
        this.port = in.readInt();
        this.ftpIp = in.readString();
        this.ftpPort = in.readInt();
        this.ftpUser = in.readString();
        this.ftpPsw = in.readString();
        this.picPort = in.readInt();
        this.project = in.readString();
    }

    public static final Parcelable.Creator<Config> CREATOR = new Parcelable.Creator<Config>() {
        @Override
        public Config createFromParcel(Parcel source) {
            return new Config(source);
        }

        @Override
        public Config[] newArray(int size) {
            return new Config[size];
        }
    };
}
